<?php
/*
 * @Description    : server
 * @Author         : QianLong
 * @Date           : 2023-05-04 10:39:14
 * @LastEditors    : QianLong
 * @Site           : http://www.21ds.cn
 * @LastEditTime   : 2023-11-07 17:25:45
 */

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use Hyperf\Server\Event;
use Hyperf\Server\Server;
use Swoole\Constant;

return [
    'mode' => SWOOLE_PROCESS,
    'servers' => [
        [
            'name' => 'http',
            'type' => Server::SERVER_HTTP,
            'host' => '0.0.0.0',
            'port' => 9501,
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
            ]
        ],
        [
            'name' => 'socket-io',
            'type' => Server::SERVER_WEBSOCKET,
            'host' => '0.0.0.0',
            'port' => 9502,
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
                Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
                Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
            ],
        ]
    ],
    'settings' => [
        Constant::OPTION_ENABLE_COROUTINE => true,
        Constant::OPTION_WORKER_NUM => 28,
        Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',
        Constant::OPTION_OPEN_TCP_NODELAY => true,
        Constant::OPTION_MAX_COROUTINE => 8000,
        Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
        Constant::OPTION_MAX_REQUEST => 4000,
        Constant::OPTION_SOCKET_BUFFER_SIZE => 1024 * 1024 * 1024,
        Constant::OPTION_BUFFER_OUTPUT_SIZE => 1024 * 1024 * 1024,
        Constant::OPTION_PACKAGE_MAX_LENGTH => 1024 * 1024 * 1024,
        Constant::OPTION_REACTOR_NUM => 12,
        Constant::OPTION_MAX_WAIT_TIME => 3,
        Constant::OPTION_MAX_CONNECTION => 3000,
        Constant::OPTION_OPEN_TCP_KEEPALIVE => true,
        Constant::OPTION_TASK_ENABLE_COROUTINE => false,
        Constant::OPTION_TCP_KEEPIDLE => 4,
        Constant::OPTION_TCP_KEEPINTERVAL => 1,
        Constant::OPTION_TCP_KEEPCOUNT => 3,
        Constant::OPTION_TASK_WORKER_NUM => 5,
        'document_root' => BASE_PATH . '/static',
        'enable_static_handler' => true,
        'heartbeat_idle_time'=>300,
        'heartbeat_check_interval'=>60
    ],
    'callbacks' => [
        Event::ON_BEFORE_START => [Hyperf\Framework\Bootstrap\ServerStartCallback::class, 'beforeStart'],
        Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
        Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
        Event::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
        Event::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
        Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
    ],
];
